package com.itheima.examination3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DormitoryManagement {
    public static void main(String[] args) {
        // 创建HashMap集合，键是宿舍号，值是宿舍里住的4个学生
        Map<String, List<Student>> dormitoryMap = new HashMap<>();

        // 创建宿舍1的学生
        List<Student> dorm1Student1s = new ArrayList<>();
        dorm1Student1s.add(new Student("张三", 18));
        dorm1Student1s.add(new Student("李四", 19));
        dorm1Student1s.add(new Student("王五", 18));
        dorm1Student1s.add(new Student("赵六", 20));

        // 创建宿舍2的学生
        List<Student> dorm2Student1s = new ArrayList<>();
        dorm2Student1s.add(new Student("陈七", 19));
        dorm2Student1s.add(new Student("周八", 18));
        dorm2Student1s.add(new Student("吴九", 20));
        dorm2Student1s.add(new Student("郑十", 19));

        // 将宿舍和学生信息放入Map
        dormitoryMap.put("宿舍1", dorm1Student1s);
        dormitoryMap.put("宿舍2", dorm2Student1s);

        // 遍历Map集合，打印每个宿舍住的学生
        System.out.println("宿舍学生分布情况：");
        for (Map.Entry<String, List<Student>> entry : dormitoryMap.entrySet()) {
            String dormitoryNumber = entry.getKey();
            List<Student> student1s = entry.getValue();

            System.out.println(dormitoryNumber + "住的学生：");
            for (Student student1 : student1s) {
                System.out.println("  " + student1);
            }
            System.out.println();
        }
    }
}
